# from importlib.resources import path
# from os import times
import muggle_ocr
# import time
import urllib


def input_vs(path,img):
    # #打开网址下载图片进行识别
    # now = str(int(time.time()))
    # n_url = str(urlS+now)
    # response = requests.get(n_url,headers=headers)
    # res = response.json()['result']
    image = urllib.request.urlopen(img)
    Image = image.read()
    #n_t = str(int(time.time()))
    n_t = 'code'
    p_name = str(path+'\\'+ n_t +'.png')
    with open(p_name,'wb') as f :
        f.write(Image)

    #打开图片进行识别
    with open(str(p_name), "rb") as f:
        captcha_bytes = f.read()
    # ModelType.Captcha 可识别4-6位验证码
    sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha)
    #输出验证码
    text = sdk.predict(image_bytes=captcha_bytes)
    return text

